package Table;


import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import java.awt.BorderLayout;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

import danhmuc.KhachHang;
import form.DSJ_FormMuaHang;
import form.DSJ_KhachHang;

import trangchu.UtilDelegate;
import trangchu.TrangChu;
import java.awt.Dimension;
import java.beans.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;


public class TKhachHang extends JPanel {
	public DefaultTableModel model;
    public JTable tableKH;
    public KhachHang khachhang;
    String[][] data = {};
    String[] columns = {"Mã KH","Họ Tên","Địa Chỉ","Điện Thoại","Fax","Email","Số Tài Khoản","Ngân Hàng"};
	public TKhachHang() {
		DSJ_KhachHang b = new DSJ_KhachHang();
		JScrollPane scrollPane = new JScrollPane();
		model = new DefaultTableModel(data, columns);
		tableKH = new JTable(model);
	
		//kich thuoc
		
		TableColumn col = tableKH.getColumnModel().getColumn(0);		col.setPreferredWidth(70);
		TableColumn col1 = tableKH.getColumnModel().getColumn(1);		col1.setPreferredWidth(236);
		TableColumn col2 = tableKH.getColumnModel().getColumn(2);		col2.setPreferredWidth(300);
		TableColumn col3 = tableKH.getColumnModel().getColumn(3);		col3.setPreferredWidth(100);
		TableColumn col4 = tableKH.getColumnModel().getColumn(4);		col4.setPreferredWidth(100);
		TableColumn col5 = tableKH.getColumnModel().getColumn(5);		col5.setPreferredWidth(200);
		TableColumn col6 = tableKH.getColumnModel().getColumn(6);		col6.setPreferredWidth(200);
		TableColumn col7 = tableKH.getColumnModel().getColumn(7);		col7.setPreferredWidth(150);
		
		tableKH.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		setLayout(new BorderLayout(0, 0));
		scrollPane.setViewportView(tableKH);
		add(scrollPane);
		
		
		
	

	
	}
	public void dskhachhang(KhachHang khachhang){
		this.khachhang = khachhang;
		DSJ_KhachHang b = new DSJ_KhachHang();
		Vector list = b.getUsers();
		Vector list2;
		model.getDataVector().removeAllElements();
		for (int i = 0; i < list.size(); i++) {
			list2 = (Vector) list.get(i);
			Object[] oPerson = {
					list2.get(0).toString(),
					list2.get(1).toString(),
					list2.get(2).toString(),
					list2.get(3).toString(),
					list2.get(4).toString(),
					list2.get(5).toString(),
					list2.get(6).toString(),
					list2.get(7).toString()};
			
			model.insertRow(0, oPerson);
			
		}
		model.fireTableDataChanged();
	}
}
